define(function () {
    return function ($compile, $scope) {
        require(["PDUtilDir/grid", "AppPathDir/video/videoInfos/support",
            "css!AppPathDir/welcome/css/welcome"], function (Grid, Support) {
            /* 查询 start */
            // $scope.search = {};
            $scope.cache = {
                types: new Array(),
                typeMap: new Map(),
                saleStatus: new Array(),
                saleStatusMap: new Map()
            };
            $scope.data = {
                products: new Array(),
                videos: new Array()
            };

            //获取类型信息
            $.ajax({
                url: getServer() + "/flea/hclv/getTourism.htmls",
                success: function (data) {
                    if (data.status != 200) {
                        return;
                    }
                    $scope.cache.types = data.data;
                    $.each(data.data, function (index, row) {
                        $scope.cache.typeMap.set(row.dictCode, row.dictName);
                    });
                    $scope.productSupport();
                }
            });
            //获取销售状态
            $.ajax({
                url: getServer() + "/flea/hclv/getSaleStatus.htmls",
                success: function (data) {
                    if (data.status != 200) {
                        return;
                    }
                    $scope.cache.saleStatus = data.data;
                    $.each(data.data, function (index, row) {
                        $scope.cache.saleStatusMap.set(row.dictCode, row.dictName);
                    });
                    $scope.productSupport();
                }
            });

            //首页数据
            $.ajax({
                url: getServer() + "/flea/hclv/video/training/selectHomeData.htmls",
                success: function (data) {
                    if (data.status != 200) {
                        return;
                    }
                    $scope.data = data.data;
                    $scope.videoSupport();
                    $scope.productSupport();
                }
            });
            //产品列表
            $scope.productSupport = function (data) {
                if ($scope.cache.saleStatus.length == 0 && $scope.cache.types.length == 0 && $scope.data.products.length == 0) {
                    return;
                }
                Grid({
                    id: "welcomeProductDiv",
                    // pageSize: 10,
                    index: true,
                    // multi: false,
                    pagination: false,
                    cache: false,
                    layout: [{
                        name: "名称",
                        field: "name"/*,
                        click : function(e) {
                            updateObj.run(e.data.row.id);
                        }*/
                    }, {
                        name: "状态",
                        field: "status",
                        width: '50px',
                        format: function (e) {
                            if ($scope.cache.saleStatus)
                                return $scope.cache.saleStatusMap.get(e.row.status);
                            return '未知(' + e.row.status + ')';
                        }
                    }, {
                        name: "类型",
                        field: "type",
                        width: '50px',
                        format: function (e) {
                            if ($scope.cache.typeMap)
                                return $scope.cache.typeMap.get(e.row.type);
                            return '未知(' + e.row.type + ')';
                        }
                    }, {
                        name: "天数",
                        width: '40px',
                        field: "travelDay"
                    }, {
                        name: "夜数",
                        width: '40px',
                        field: "travelNight"
                    }, {
                        name: "成人价格",
                        width: '60px',
                        field: "salePriceAdult"
                    }, {
                        name: "儿童价格",
                        width: '60px',
                        field: "salePriceChild"
                    }, {
                        name : "创建人",
                        width: '60px',
                        field : "createUserName"
                    }, {
                        name : "创建时间",
                        width: '60px',
                        field : "createTime"
                    }],
                    toolbar: [],
                    data: $scope.data.products
                });
            };
            //视频列表
            $scope.videoSupport = function (data) {
                if ($scope.data.products.length == 0) {
                    return;
                }
                Grid({
                    id: "videoProductDiv",
                    // pageSize: 10,
                    index: true,
                    // multi: false,
                    pagination: false,
                    cache: false,
                    layout : [ {
                        name : "视频名称",
                        field : "videoName"/*,
                        click : function(e) {
                            updateObj.run(e.data.row);
                        }*/
                    }/*, {
                        name : "产品名称",
                        field : "productName",
                        sort : true
                    }*/, {
                        name : "介绍",
                        field : "videoIntroduce",
                        width : "10%"
                    }, {
                        name : "创建人",
                        field : "createUser"
                    }, {
                        name : "创建时间",
                        field : "createTime"
                    }],
                    toolbar: [],
                    data: $scope.data.videos
                });
            };
        })
    }
});